package com.retail.marketing.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.marketing.common.domain.TCouponType;
import com.retail.marketing.server.service.ITCouponTypeService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 优惠券类型管理Controller
 *
 * @author retail
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/couponType")
public class TCouponTypeController extends BaseController
{
    @Autowired
    private ITCouponTypeService tCouponTypeService;

    /**
     * 查询优惠券类型管理列表
     */
    @RequiresPermissions("marketing:couponType:list")
    @GetMapping("/list")
    public TableDataInfo list(TCouponType tCouponType)
    {
        startPage();
        List<TCouponType> list = tCouponTypeService.selectTCouponTypeList(tCouponType);
        return getDataTable(list);
    }

    /**
     * 导出优惠券类型管理列表
     */
    @RequiresPermissions("marketing:couponType:export")
    @Log(title = "优惠券类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCouponType tCouponType)
    {
        List<TCouponType> list = tCouponTypeService.selectTCouponTypeList(tCouponType);
        ExcelUtil<TCouponType> util = new ExcelUtil<TCouponType>(TCouponType.class);
        util.exportExcel(response, list, "优惠券类型管理数据");
    }

    /**
     * 获取优惠券类型管理详细信息
     */
    @RequiresPermissions("marketing:couponType:query")
    @GetMapping(value = "/{couponTypeId}")
    public Result getInfo(@PathVariable("couponTypeId") Long couponTypeId)
    {
        return success(tCouponTypeService.selectTCouponTypeByCouponTypeId(couponTypeId));
    }

    /**
     * 新增优惠券类型管理
     */
    @RequiresPermissions("marketing:couponType:add")
    @Log(title = "优惠券类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody TCouponType tCouponType)
    {
        return toAjax(tCouponTypeService.insertTCouponType(tCouponType));
    }

    /**
     * 修改优惠券类型管理
     */
    @RequiresPermissions("marketing:couponType:edit")
    @Log(title = "优惠券类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TCouponType tCouponType)
    {
        return toAjax(tCouponTypeService.updateTCouponType(tCouponType));
    }

    /**
     * 删除优惠券类型管理
     */
    @RequiresPermissions("marketing:couponType:remove")
    @Log(title = "优惠券类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponTypeIds}")
    public Result remove(@PathVariable Long[] couponTypeIds)
    {
        return toAjax(tCouponTypeService.deleteTCouponTypeByCouponTypeIds(couponTypeIds));
    }
}
